package cn.hbwe.util;

import lombok.Data;

@Data
public class Result<T> {
    private Integer code;//1表示成功，0表示失败

    private String msg;//返回信息

    private T data;//返回数据

    /**
     * 数据返回
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(1);
        result.setData(data);
        return result;
    }

    /**
     * 信息返回
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(String msg) {
        Result<T> result = new Result<>();
        result.setCode(1);
        result.setMsg(msg);
        return result;
    }

    /**
     * 失败返回
     * @param msg
     * @param <T>
     * @return
     */
    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }
}
